#!/bin/bash

echo "ROSGUI_ROOT_PATH is $ROSGUI_ROOT_PATH"

build_libdrm_PATH=$(realpath "$0")
LIBDRM_SOURCE_DIR=$(dirname "$build_libdrm_PATH")

echo "current directory is $LIBDRM_SOURCE_DIR"

PKGS_COMPILE_DIR=$ROSGUI_ROOT_PATH/out/compile_dir
LIBDRM_COMPILE_DIR=$PKGS_COMPILE_DIR/libdrm-2.4.124
TARGET_INSTALL_DIR=$ROSGUI_ROOT_PATH/out/target/usr

CROSS_FILE_FULLNAME=$LIBDRM_SOURCE_DIR/cross_file.txt

arm-arago-linux-gnueabi-gcc --version

mkdir -p $PKGS_COMPILE_DIR

cd $LIBDRM_SOURCE_DIR

tar -xf libdrm-2.4.124.tar.xz -C $PKGS_COMPILE_DIR

cd -

cd $LIBDRM_COMPILE_DIR

meson setup build \
    --cross-file $CROSS_FILE_FULLNAME \
    --prefix=$TARGET_INSTALL_DIR \
    -Dintel=disabled \
    -Dradeon=disabled \
    -Damdgpu=disabled \
    -Dnouveau=disabled \
    -Detnaviv=disabled \
    -Dexynos=disabled \
    -Dfreedreno=disabled \
    -Dtegra=disabled \
    -Dvc4=disabled \
    -Dvmwgfx=disabled \
    -Dtests=false

cd build

ninja

ninja install

cd 
